//****************************************************************************
// File Name: Winery.cpp
// Wine Tours project
// Group #2: Allen McLennan, Ryan Neal, Mike Matz
// CS 1C
// April 28, 2010
// Implementation of Winery class
//****************************************************************************

#include "Winery.h"

Winery::Winery() : id(0), name (), wines(), distance(0.0),
					distances(), wineNum(0){}

Winery::Winery(int wineryId) : id(wineryId), name (), wines(),distance(0.0),
								distances(), wineNum(0){}


/************************************************
 * toString
 * _____________________________________________
 * Converts a character stream to a string.
 * 	Helper for overloaded <<
 * _____________________________________________
 * PRE-CONDITIONS
 * 	name: name of the winery
 * _____________________________________________
 * POST-CONDITIONS
 * none
 ***********************************************/

string Winery::toString()
{
	string strName;

	strName = name;

	return strName;
}

//GetDistanceToWinery
//	Returns the distance to a specified winery

float Winery::GetDistanceToWinery(int wineryId)
{
	return distances[wineryId - 1];
}

//SetDistanceToWinery
//	User sets the distance to specified winery

void Winery::SetDistanceToWinery(int wineryId, float dist)
{
	distances[wineryId - 1] = dist;
}

//SetName
//	User sets the name of the winery

void Winery::SetName(const char *wName)
{
	strcpy(name, wName);
}

void Winery::SetId(int wineryId)
{
	id = wineryId;
}

//GetName
//	Returns a pointer to the name of the winery

char* Winery::GetName()
{
	return name;
}

int Winery::GetId() {
	return id;
}

void Winery::SetDistance(float dist) {
	distance = dist;
}

float Winery::GetDistance() {
	return distance;
}

ostream& operator<<(ostream& osObject, Winery& winery)
{
	osObject << winery.toString() << endl
			 << "Winery id:" << winery.id << endl
			 << setfill('=') << setw(30) << '='
			 << setfill('.');

	for(unsigned int i = 0; i < winery.wineNum; i++)
	{
		osObject << winery.wines[i].vintage << ' '
				 << setw(25) << left << winery.wines[i].wineName
				 << '$' << winery.wines[i].price << endl;
	}

	cout << setfill('=') << setw(30) << '=' << right << setfill(' ')
		 << "\n\n";

	return osObject;
}

//AddWine
//Adds a wine to the array. Updates wineNum.
void Winery::AddWine(Wine newWine)
{
	if(wineNum < MAX_WINES)
	{
		strcpy(wines[wineNum].wineName, newWine.wineName);
		wines[wineNum].vintage = newWine.vintage;
		wines[wineNum].price = newWine.price;

		wineNum++;
	}
}

//InitializeWine
//Initializes the wines array to ' ', 0, and 0.0
void Winery::InitializeWine()
{
	for(int i = 0; i < MAX_WINES; i++)
	{
		strcpy(wines[i].wineName," ");
		wines[i].vintage = 0;
		wines[i].price = 0.00;
	}
}

//GetWine
//Returns a wine from the list of wines
Wine Winery::GetWine(int index)
{
	return wines[index];
}

//OutputWineList
//Outputs the list of wines

void Winery::OutputWineList()
{
	int count;		//Counts number of wines

	count = 1;

	for(int i = 0; i < wineNum; i++)
	{
		cout << count << ". " << left
			 << setw(5) << wines[i].vintage << setfill('.')
			 << setw(25)
			 << wines[i].wineName << '$' << wines[i].price << endl
			 << setfill(' ');

		count++;
	}

	cout << right << endl;
}

//GetWineNum
//Returns the number of wines
int Winery::GetWineNum()
{
	return wineNum;
}
